package com.bytic.miaosha.mapper;

import com.bytic.miaosha.vo.GoodsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GoodsMapper {

    @Select("SELECT g.*, mg.miaosha_price, mg.start_date, mg.end_date, mg.stock_count FROM miaosha_goods mg LEFT JOIN" +
            " goods g ON mg.goods_id = g.id")
    public List<GoodsVO> listGoodsVo();

    @Select("SELECT g.*, mg.miaosha_price, mg.start_date, mg.end_date, mg.stock_count FROM miaosha_goods mg LEFT JOIN" +
            " goods g ON mg.goods_id = g.id WHERE g.id = #{goodsid}")
    public GoodsVO getGoodsVoByGoodsId(long goodsid);

    @Update("update miaosha_goods set stock_count = stock_count - 1 where goods_id = #{goodsId} and stock_count > 0")
    public int reduceStock(Long goodsId);
}
